home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / earcd / misc / emu / arosdev.lha / AROS / workbench / c / newshell.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  2KB  |  117 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: newshell.c,v 1.6 1997/01/27 00:22:37 ldp Exp $
  4.     $Log: newshell.c,v $
  5.     Revision 1.6  1997/01/27 00:22:37  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.5  1996/10/24 15:32:25  aros
  9.     Fixed some warnings about int/ptr conversions
  10.  
  11.     Revision 1.4  1996/09/17 16:43:01  digulla
  12.     Use general startup code
  13.  
  14.     Revision 1.3  1996/09/13 17:52:11  digulla
  15.     Use IPTR
  16.  
  17.     Revision 1.2  1996/08/01 17:40:45  digulla
  18.     Added standard header for all files
  19.  
  20.     Desc:
  21.     Lang:
  22. */
  23. #include <exec/memory.h>
  24. #include <proto/exec.h>
  25. #include <dos/dosextens.h>
  26. #include <dos/dostags.h>
  27. #include <proto/dos.h>
  28. #include <utility/tagitem.h>
  29.  
  30. int main (int argc, char ** argv)
  31. {
  32.     STRPTR args[2]={ "CON:", "S:Shell-Startup" };
  33.     struct RDArgs *rda;
  34.     BPTR lock, in, out, shell;
  35.     STRPTR s1, s2, s3, buf;
  36.     struct Process *process;
  37.     LONG error=RETURN_ERROR;
  38.  
  39.     rda=ReadArgs("WINDOW,FROM",(IPTR *)args,NULL);
  40.     if(rda!=NULL)
  41.     {
  42.     s1=s2=(STRPTR)args[1];
  43.     while(*s2++)
  44.         ;
  45.     buf=(STRPTR)AllocVec(6+2*(s2-s1),MEMF_ANY);
  46.     if(buf!=NULL)
  47.     {
  48.         CopyMem("FROM ",buf,5);
  49.         s3=buf+5;
  50.         s2=s1;
  51.         *s3++='\"';
  52.         while(*s1)
  53.         {
  54.         if(*s1=='*'||*s1=='\"'||*s1=='\n')
  55.             *s3++='*';
  56.         if(*s1=='\n')
  57.             *s3++='n';
  58.         else
  59.             *s3++=*s1;
  60.         s1++;
  61.         }
  62.         *s3++='\"';
  63.         *s3=0;
  64.  
  65.         shell=LoadSeg("c:shell");
  66.         if(shell)
  67.         {
  68.         out=Open(args[0],MODE_READWRITE);
  69.         if(out)
  70.         {
  71.             /* Clone output filehandle */
  72.             lock=DupLockFromFH(out);
  73.             if(lock)
  74.             {
  75.             in=OpenFromLock(lock);
  76.             if(!in)
  77.                 UnLock(lock);
  78.             }else
  79.             in=0;
  80.             if(in)
  81.             {
  82.             struct TagItem tags[]=
  83.             {
  84.                 { NP_Arguments, 0 },
  85.                 { NP_Input, 0 },
  86.                 { NP_Output, 0 },
  87.                 { NP_Error, 0 },
  88.                 { NP_Seglist, 0 },
  89.                 { NP_Cli, 1 },
  90.                 { TAG_END, 0 }
  91.             };
  92.             tags[0].ti_Data=(IPTR)buf;
  93.             tags[1].ti_Data=(IPTR)in;
  94.             tags[2].ti_Data=(IPTR)out;
  95.             tags[4].ti_Data=(IPTR)shell;
  96.             process=CreateNewProc(tags);
  97.             if(process!=NULL)
  98.             {
  99.                 out=in=shell=0;
  100.                 error=0;
  101.             }
  102.             Close(in);
  103.             }
  104.             Close(out);
  105.         }
  106.         UnLoadSeg(shell);
  107.         }
  108.         FreeVec(buf);
  109.     }
  110.     FreeArgs(rda);
  111.     }else
  112.     error=RETURN_FAIL;
  113.     if(error)
  114.     PrintFault(IoErr(),"NewShell");
  115.     return error;
  116. }
  117.